from pylab import *
import scipy.ndimage
from fast12 import detect
import sys

import simplejson

if __name__ == '__main__':


    if len(sys.argv) < 3:
        print sys.argv[0], '<job_file.json> <frame_number>'
        raise Exception('Insufficient number of parameters')

    finput = open(sys.argv[1])
    job_params = simplejson.load(finput)
    finput.close()

    fileroot = job_params['root_directory']


    framenum = int(sys.argv[2])

    filename = fileroot+'/frames/'+job_params['filename_format']%framenum
    output = fileroot+'/fastcorners/'+job_params['filename_format']%framenum

    img_color = imread(filename)
    img_gray = 256. * img_color.sum(2)

    features = detect(img_gray, 40., do_nonmax=1)

    savetxt(output, features[0])
